import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Vocabulary {

	
	User user = new User();

	public void enroll(String id, int level, String word, String mean) {
		String string_level = null;
		if (level == 3)
			string_level = "high";
		if (level == 2)
			string_level = "mid";
		if (level == 1)
			string_level = "low";

		try {
			FileWriter bw = new FileWriter("voca.txt", true);

			bw.append(id);
			bw.append("/");
			bw.append(string_level);
			bw.append("/");
			bw.append(word);
			bw.append("/");
			bw.append(mean);
			bw.append("\n");

			bw.close();

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public void voca(String id) {
		System.out
				.println("Select 1~3 1.My vocabulary 2. addvoca 3. remove voca");
		Scanner scanner = new Scanner(System.in);
		int i = scanner.nextInt();

		if (i == 1)
			this.show(id);
		else if (i == 2)
			this.addVoca(id);
		else if (i == 3)
			this.removeVoca(id);
		else
			System.out.println("Range error. you should insert 1~3");
		this.voca(id);

	}

	public void show(String id) {
		try {

			String line = "";
			BufferedReader br = new BufferedReader(new FileReader("voca.txt"));
			String voca[] = new String[4];
			while ((line = br.readLine()) != null) {

				voca = line.split("/");
				if (voca[0].equals(id)) {

					System.out.println("level : " + voca[1]);
					System.out.println("words : " + voca[2]);
					System.out.println("mean : " + voca[3]);

				}

			}

			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public void addVoca(String id) {
		Scanner scanner = new Scanner(System.in);

		String word;
		String mean;
		int choice;

		System.out.print("What words do you want to add? : ");
		word = scanner.nextLine();
		System.out.print("\n What means your word? : ");
		mean = scanner.nextLine();

		try {
			FileWriter bw = new FileWriter("voca.txt", true);

			bw.append(id);
			bw.append("/");
			bw.append("user add");
			bw.append("/");
			bw.append(word);
			bw.append("/");
			bw.append(mean);
			bw.append("\n");

			bw.close();

		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println("do you want to add another voca? 1. yes 2. no");
		choice = scanner.nextInt();

		if (choice == 1)
			this.addVoca(id);
		if (choice == 2)
//			user.start();

		scanner.close();
	}

	public void removeVoca(String id) {

	}

}
